package com.cy.cy2025.activity

import android.Manifest
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.cy.cy2025.databinding.ActivityPermissionTestBinding
import com.cy.cy2025.util.PermissionUtil
import com.cy.cy2025.util.PermissionsCallback
import com.cy.cy2025.util.ToastUtil

class PermissionTestActivity : AppCompatActivity() {

    val binding by lazy { ActivityPermissionTestBinding.inflate(layoutInflater) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)


        binding.btn1.setOnClickListener {

            PermissionUtil.requestPermissions(object : PermissionsCallback {
                override fun onSuccess() {
                    ToastUtil.showShort("获取成功")
                    binding.tvResult.text = "获取成功"
                }

                override fun onFailure(failures: List<String>, forbiddings: List<String>) {
                    ToastUtil.showShort("获取失败")
                    binding.tvResult.text = "获取失败的权限:$failures \n\n其中被拒绝并禁止的权限:$forbiddings"
                }

            }, Manifest.permission.CAMERA)
        }

        binding.btn2.setOnClickListener {

            PermissionUtil.requestPermissions(object : PermissionsCallback {
                override fun onSuccess() {
                    ToastUtil.showShort("获取成功")
                    binding.tvResult.text = "获取成功"
                }

                override fun onFailure(failures: List<String>, forbiddings: List<String>) {
                    ToastUtil.showShort("获取失败")
                    binding.tvResult.text = "获取失败的权限:$failures \n\n其中被拒绝并禁止的权限:$forbiddings"
                }

            }, Manifest.permission.RECORD_AUDIO)
        }

        binding.btn3.setOnClickListener {

            PermissionUtil.requestPermissions(
                object : PermissionsCallback {
                    override fun onSuccess() {
                        ToastUtil.showShort("获取成功")
                        binding.tvResult.text = "获取成功"
                    }

                    override fun onFailure(failures: List<String>, forbiddings: List<String>) {
                        ToastUtil.showShort("获取失败")
                        binding.tvResult.text = "获取失败的权限:$failures \n\n其中被拒绝并禁止的权限:$forbiddings"
                    }

                },
                Manifest.permission.READ_CONTACTS,
                Manifest.permission.CALL_PHONE,
                Manifest.permission.READ_CALENDAR
            )
        }
    }
}